Skip to content

convert enchant resources to objects #5528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

remicollet
Copy link
Member

@remicollet remicollet commented May 5, 2020

This creates 2 new classes

  • EnchantBroker
  • EnchantDict

* @deprecated
*/
function enchant_broker_get_dict_path($broker, int $name): string|false {}
function enchant_broker_get_dict_path(EnchantBroker$broker, int $name): string|false {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space (same for the two stubs below)

Suggested change
function enchant_broker_get_dict_path(EnchantBroker$broker, int $name): string|false {}
function enchant_broker_get_dict_path(EnchantBroker $broker, int $name): string|false {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, good catch

@remicollet
Copy link
Member Author

I also choose to deprecate enchant_broker_free and enchant_broker_free_dict, these don't make sense, especially as they result in an unusable object, better and simpler to unset the variable when not needed anymore.

@remicollet
Copy link
Member Author

OO API added in latest commit.

@remicollet remicollet mentioned this pull request May 5, 2020
@remicollet
Copy link
Member Author

Help welcome on the leak reported by travis (cannot reproduce locally)

Else, ready for review.

@cmb69
Copy link
Member

cmb69 commented May 5, 2020

Help welcome on the leak reported by travis (cannot reproduce locally)

The zend_objects have to be released in the free_obj handlers:

 ext/enchant/enchant.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c
index 795b149b87..9a092573d3 100644
--- a/ext/enchant/enchant.c
+++ b/ext/enchant/enchant.c
@@ -170,6 +170,7 @@ static void php_enchant_broker_free(zend_object *object) /* {{{ */
 		if (broker->pbroker) {  /* may have been freed by enchant_broker_free */
 			enchant_broker_free(broker->pbroker);
 		}
+		zend_object_std_dtor(object);
 	}
 }
 /* }}} */
@@ -189,6 +190,7 @@ static void php_enchant_dict_free(zend_object *object) /* {{{ */
 				zval_ptr_dtor(&dict->zbroker);
 			}
 		}
+		zend_object_std_dtor(object);
 	}
 }
 /* }}} */

I also think that ENCHANT_MYSPELL and ENCHANT_ISPELL should be deprecated right away, since they are only meaningful for enchant_broker_set_dict_path() and enchant_broker_get_dict_path() which have already been deprecated (besides that the ispell provider is no longer supported as of Enchant 2.0.0):

 ext/enchant/enchant.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c
index 795b149b87..6a490fb833 100644
--- a/ext/enchant/enchant.c
+++ b/ext/enchant/enchant.c
@@ -223,8 +223,8 @@ PHP_MINIT_FUNCTION(enchant)
 	enchant_dict_handlers.free_obj = php_enchant_dict_free;
 	enchant_dict_handlers.clone_obj = NULL;
 
-	REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT |  CONST_DEPRECATED);
+	REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT | CONST_DEPRECATED);
 #ifdef HAVE_ENCHANT_GET_VERSION
 	REGISTER_STRING_CONSTANT("LIBENCHANT_VERSION", enchant_get_version(), CONST_CS | CONST_PERSISTENT);
 #endif

@remicollet remicollet force-pushed the issue-enchant-obj branch from 2990352 to 029964a Compare May 6, 2020 06:11
@remicollet
Copy link
Member Author

@cmb69 thanks again.

PR rebased

@remicollet
Copy link
Member Author

Replaced by #5533

@remicollet remicollet closed this May 6, 2020
@remicollet remicollet deleted the issue-enchant-obj branch May 6, 2020 11:28
@carusogabriel carusogabriel modified the milestone: PHP 8.0 May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants